package net.cyan.proteus.base;

import net.cyan.proteus.*;
import net.cyan.proteus.compile.*;
import net.cyan.proteus.execute.BaseTemplateExecutor;

/**
 * 
 * @author camel
 * @date 2008-4-10
 */
public class BaseTemplateContainer extends TemplateContainer
{
    public BaseTemplateContainer(TemplateLoader loader, TemplateMaker marker)
    {
        super(loader, marker);
    }

    public BaseTemplateContainer(BaseTemplateLoader loader, boolean compile)
    {
        super(loader, compile ? new BaseTemplateCompiler(DefaultClassMaker.getInstance()) : new BaseTemplateExecutor());
    }

    public BaseTemplateContainer(BaseTemplateLoader loader)
    {
        this(loader, true);
    }

    public BaseTemplateContainer(String root, String ext, String charset, boolean logic, boolean script,
                                 boolean compile)
    {
        this(createLoader(root, ext, charset, logic, script), compile);
    }

    public BaseTemplateContainer(String root, String ext, String charset, boolean compile)
    {
        this(createLoader(root, ext, charset), compile);
    }

    public BaseTemplateContainer(String root, String ext, String charset, boolean logic, boolean script)
    {
        this(createLoader(root, ext, charset, logic, script), true);
    }

    public BaseTemplateContainer(String root, boolean compile)
    {
        this(createLoader(root), compile);
    }

    public BaseTemplateContainer(String root, String ext, boolean compile)
    {
        this(createLoader(root, ext), compile);
    }

    public BaseTemplateContainer(String root)
    {
        this(createLoader(root), true);
    }

    public BaseTemplateContainer(String root, String ext)
    {
        this(createLoader(root, ext), true);
    }

    protected static BaseTemplateLoader createLoader(String root, String ext, String charset, boolean logic,
                                                     boolean script)
    {
        return new BaseTemplateLoader(root, ext, new DefaultTemplateParser(logic, script), charset);
    }

    public static BaseTemplateLoader createLoader(String root, String ext, String charset)
    {
        return new BaseTemplateLoader(root, ext, new DefaultTemplateParser(), charset);
    }

    public static BaseTemplateLoader createLoader(String root, String ext)
    {
        return new BaseTemplateLoader(root, ext, new DefaultTemplateParser());
    }

    public static BaseTemplateLoader createLoader(String root)
    {
        return new BaseTemplateLoader(root, "ptl", new DefaultTemplateParser());
    }

    protected void initContext(TemplateContext context) throws Exception
    {
        TagContext tagContext = TagContext.getTagContext(context);
        tagContext.addFactory(AutoTagProcessorFactory.INSTANCE);
        tagContext.addFactory(IncludeTagProcessorFactory.INSTANCE);
    }
}
